﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CinemaSystem
{
    public partial class xwxg : Form
    {
        public xwxg()
        {
            InitializeComponent();
        }
        string sqlstr;
        DataTable dt = new DataTable();
        private void xwxg_Load(object sender, EventArgs e)
        {
          
            sqlstr = string.Format("select * from Journalism");
            dt = DBHelper.GetDataTable(sqlstr);

            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = dt;
           
        }

        private void 修改时间ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
        
        private void 修改作者ToolStripMenuItem_Click(object sender, EventArgs e)
        {
       
        }
       public static int id;
        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            id = e.RowIndex;
        }
        int i;
        
        private void button1_Click(object sender, EventArgs e)
        {
            
            sqlstr = string.Format("update Journalism set author = '{0}' where Journalismid ={1}",txtzuo.Text,dt.Rows[id]["Journalismid"].ToString());
            i = DBHelper.ExecuteNonQuery(sqlstr);
            if (i>0)
            {
                MessageBox.Show("修改成功");
                sqlstr = "select * from Journalism";
                dt = DBHelper.GetDataTable(sqlstr);
                dataGridView1.DataSource = dt;
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }

        private void txtzuo_TextChanged(object sender, EventArgs e)
        {
            
            dt = DBHelper.GetDataTable(sqlstr);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
          



        }

        private void button2_Click(object sender, EventArgs e)
        {
            sqlstr = string.Format("update Journalism set Journalismname= '{0}' where Journalismid ={1}", txtbiao.Text, dt.Rows[id]["Journalismid"].ToString());
            i = DBHelper.ExecuteNonQuery(sqlstr);
            if (i > 0)
            {
                MessageBox.Show("修改成功");
                sqlstr = "select * from Journalism";
                dt = DBHelper.GetDataTable(sqlstr);
                dataGridView1.DataSource = dt;
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            sqlstr = string.Format("update Journalism set Newscontent= '{0}' where Journalismid ={1}", txtnei.Text, dt.Rows[id]["Journalismid"].ToString());
            i = DBHelper.ExecuteNonQuery(sqlstr);
            if (i > 0)
            {
                MessageBox.Show("修改成功");
                sqlstr = "select * from Journalism";
                dt = DBHelper.GetDataTable(sqlstr);
                dataGridView1.DataSource = dt;
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string sqlstr = string.Format("delete from Journalism where Journalismid={0}", dt.Rows[id]["Journalismid"].ToString());
            int i = DBHelper.ExecuteNonQuery(sqlstr);
            if (i > 0)
            {

                sqlstr = "select * from Journalism";
                dt = DBHelper.GetDataTable(sqlstr);
                dataGridView1.DataSource = dt;


            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            MainGLY MainGLY = new MainGLY();
            MainGLY.Show();
            this.Hide();
        }
    }
}
